package shared

import upickle.default._

import scala.collection.immutable.SeqMap

/**
 * Created by yz on 8/10/2021
 */
object Pojo {

  case class ChrData(chr: String, start: Int, end: Int)

  implicit val seqMapReadWrite: ReadWriter[SeqMap[String, String]] = {
    readwriter[ujson.Obj].bimap[SeqMap[String, String]](x => {
      val ts = x.toList.map { case (k, v) =>
        (k, ujson.Str(v))
      }
      ujson.Obj.from(ts)
    }, y => {
      val ts = y.value.map { case (k, v) =>
        (k, v.str)
      }
      SeqMap.from(ts)
    })
  }

  case class CellData(value: ujson.Value, rowspan: Int)

  object CellData {

    implicit val rw = macroRW[CellData]

  }

  object GetFileData {

    case class RawResponse(map: SeqMap[String, String], array: List[Map[String, String]])

    implicit val rawResponseRw = macroRW[RawResponse]

    case class Response(map: SeqMap[String, String], array: List[Map[String, CellData]])

    implicit val responseRw = macroRW[Response]

  }

}
